package cn.tedu.waimai.controller;


import cn.tedu.waimai.entity.User;
import cn.tedu.waimai.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 用户相关操作
 */

@RestController
public class UserController {

    @Autowired
    UserMapper mapper;

    @RequestMapping("/reg")
    public String reg(User user){
        User u=mapper.selectByUsername(user.getUsername());
        if(u!=null){
            return "此用户名已被注册！";
        }
        System.out.println(user);
        mapper.insertUser(user);
        return "注册成功！";
    }

    @RequestMapping("/login")
    public String login(User user){
        User u=mapper.selectByUsername(user.getUsername());
        if(u!=null){
            if(u.getPassword().equals(user.getPassword())){
                return "登陆成功";
            }
            return "密码错误！";
        }
        return "此用户不存在！";
    }
}
